<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>key方法</title>
</head>

<body>
  <script>
    // 用于获取对象自身所有的属性 
    var obj = {
      id: 1,
      pname: '小米',
      price: 1999,
      num: 20000
    };
    var arr = Object.keys(obj);
    console.log(arr);  //(4) ["id", "pname", "price", "num"]
  </script>
</body>

</html>